package com.wxy.aop注解;

import org.aspectj.lang.JoinPoint;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component("advice")
@Aspect
public class Advice {
	@Pointcut("execution(* com.wxy.aop注解.userDaoImpl.*(..))")
	public void pointcut() {}
	@Before("pointcut()")
	public void before(JoinPoint jointPoint) {
		System.out.print("这是前置通知");
		System.out.print("目标类为:"+jointPoint.getTarget());
		System.out.println(",被植入增强的目标方法为"+jointPoint.getSignature().getName());
	}
	@AfterReturning("pointcut()")
	public void afterReturning(JoinPoint jointPoint) {
		System.out.print("这是返回通知(方法不出现异常时调用)！");
		System.out.println(",被植入增强的目标方法为"+jointPoint.getSignature().getName());
	}
	@Around("pointcut()")
	public Object around(ProceedingJoinPoint point) throws Throwable {
		System.out.println("环绕通知之前的部分");
		Object object=point.proceed();
		System.out.println("环绕通知之后的部分");
		return object;
	}
	@After("pointcut()")
	public void after() {
		System.out.println("这是后置通知");
	}
	@AfterThrowing("pointcut()")
	public void afterException() {
		System.out.println("异常通知");
	}
}
